package org.ymf.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.beans.BeanUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.layuiframework.stereotype.elasticsearch.ElasticsearchRecord;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 帖子
 * </p>
 *
 * @author Malphite
 * @since 2023-08-01
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="Post对象", description="帖子")
public class Post extends ElasticsearchRecord implements Serializable {

    private static final long serialVersionUID = 1L;

    @ExcelProperty(value = "id")
    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ExcelProperty(value = "标题")
    @ApiModelProperty(value = "标题")
    private String title;

    @ExcelProperty(value = "内容")
    @ApiModelProperty(value = "内容")
    private String content;

    @ExcelProperty(value = "标签列表（json 数组）")
    @ApiModelProperty(value = "标签列表（json 数组）")
    private String tags;

    @ExcelProperty(value = "点赞数")
    @ApiModelProperty(value = "点赞数")
    @TableField("thumbNum")
    private Integer thumbnum;

    @ExcelProperty(value = "收藏数")
    @ApiModelProperty(value = "收藏数")
    @TableField("favourNum")
    private Integer favournum;

    @ExcelProperty(value = "创建用户 id")
    @ApiModelProperty(value = "创建用户 id")
    @TableField("userId")
    private Long userid;

    @ExcelProperty(value = "创建时间")
    @ApiModelProperty(value = "创建时间")
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createtime;

    @ExcelProperty(value = "更新时间")
    @ApiModelProperty(value = "更新时间")
    @TableField(value = "updateTime", fill = FieldFill.INSERT_UPDATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date updatetime;

    @ExcelProperty(value = "是否删除")
    @ApiModelProperty(value = "是否删除")
    @TableField("isDelete")
    @TableLogic
    private Integer isdelete;


    /**
     * 将{@linkplain Post 数据库映射对象} 转化为 {@linkplain PostEs Elasticsearch映射对象}
     */
    public PostEs transform(){
        PostEs entity = new PostEs();
        BeanUtils.copyProperties(this, entity);
        return entity;
    }
}
